import request from '@/utils/request'
// spu组件
// 获spu对应的取售卖属性列表
export const getSaleAttrList = (spuId) =>
  request({ url: `/admin/product/spuSaleAttrList/${spuId}`, method: 'get' })

// 获取spu图片列表
export const getSpuImageList = (spuId) =>
  request({ url: `/admin/product/spuImageList/${spuId}`, method: 'get' })

// 根据3个ID,获取平台属性列表
export const getAttrList = (category1Id, category2Id, category3Id) =>
  request({
    url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`,
    method: 'get'
  })

// 添加sku
export const addSkuInfo = (data) =>
  request({ url: `/admin/product/saveSkuInfo`, method: 'post', data })

// 查询spu所对应的sku列表
export const getSkuListBySpuId = (spuId) =>
  request({ url: `/admin/product/findBySpuId/${spuId}`, method: 'get' })

// sku组件
// 获取sku展示列表
export const getSkuList = (page, limit) =>
  request({ url: `/admin/product/list/${page}/${limit}`, method: 'get' })

// 上架或者下架sku
export const skuOnSaleOrCancelSale = (skuId, isOnSale) =>
  request({
    url: isOnSale
      ? `/admin/product/onSale/${skuId}`
      : `/admin/product/cancelSale/${skuId}`,
    method: 'get'
  })

// 编辑sku信息
//根据skuid获取sku信息
export const getSkuInfoById = (skuId) =>
  request({ url: `/admin/product/getSkuById/${skuId}`, method: 'get' })

export const upDataSkuInfo = (data) =>
  request({ url: `/admin/product/updateSkuInfo`, method: 'post', data })

// 根据平台属性id(attrid)获取其对应的属性值列表
export const getAttrValueList = (attrId) =>
  request({ url: `/admin/product/getAttrValueList/${attrId}`, method: 'get' })

// 修改sku
export const updataSkuInfo = (data) =>
  request({ url: `/admin/product/updateSkuInfo`, method: 'post', data })

// 删除sku
export const delSkuInfo = (skuId) =>
  request({ url: `/admin/product/deleteSku/${skuId}`, method: 'DELETE' })

//搜索sku
export const searchSku = (keyword) =>
  request({
    url: `/admin/product/inner/findSkuInfoByKeyword/${keyword}`,
    method: 'get'
  })
